package com.my.netty.optimize.config;

import com.my.netty.optimize.protocol.Serializer;

import java.io.InputStream;
import java.util.Properties;

public class Config {
    private static Properties properties;

    static {
        try (
                InputStream in = Config.class.getResourceAsStream("/application.properties")
        ) {
            properties = new Properties();
            properties.load(in);
        } catch (Exception e) {
            throw new ExceptionInInitializerError();
        }
    }

    public static int getServerPort() {
        String val = properties.getProperty("server.port");
        return val == null ? 8080 : Integer.parseInt(val);
    }

    public static Serializer.Algorithm getSerializerAlgorithm() {
        String val = properties.getProperty("serializer.algorithm");
        return val == null ? Serializer.Algorithm.JAVA : Serializer.Algorithm.valueOf(val);
    }
}
